package com.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.dao.factory.ConnectionFactory;
import com.dao.generic.GenericDAO;
import com.model.Ano;

public class AnoDAO extends GenericDAO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4434709082705688500L;


	
	public List<Ano> retornaAnos() throws SQLException {
		List<Ano> anos = new ArrayList<Ano>();

		Connection conn = null;
		PreparedStatement pstm = null;
		ResultSet rs;

		StringBuilder sb = new StringBuilder();

		sb.append(" SELECT  ")
		.append(" ano_id as id ")
		.append(", descricao as descricao ")
		.append(" FROM Ano ");
	

		try {

			conn = ConnectionFactory.getConnection();
			pstm = conn.prepareStatement(sb.toString());

			rs = pstm.executeQuery();

			while (rs.next()) {
				Ano ano = new Ano();
				ano.setId(rs.getLong("id"));
				ano.setDescricao(rs.getString("descricao"));
				anos.add(ano);
			}

		} catch (Exception e) {

			e.getMessage();
		} finally {

			pstm.close();
			conn.close();
		}

		return anos;
		
	}

}
